/*
 * FriendPanel.java
 *
 * Created on August 28, 2008, 3:42 PM
 */

package jturbofile.gui2;

import java.awt.Color;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
 *
 * @author  jbk
 */
public class FriendPanel extends javax.swing.JPanel {
    private Color backgroundNormal = new Color(238,238,238);
    private Color backgroundHighlight = new Color(250,250,255);


    /** Creates new form FriendPanel */
    public FriendPanel(Friend friend) {
        initComponents();
        friendName.setText(friend.getName());
        transferPanel.add(new TransferPanel(new Transfer()));
        
        friendName.addMouseListener(new NamePopupListener());
    }
    
    class NamePopupListener extends MouseAdapter {
        public void mousePressed(MouseEvent e) {
            maybeShowPopup(e);
        }

        public void mouseReleased(MouseEvent e) {
            maybeShowPopup(e);
        }

        private void maybeShowPopup(MouseEvent e) {
            if (e.isPopupTrigger()) {
                friendPopup.show(e.getComponent(),
                           e.getX(), e.getY());
            }
        }
    }    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        friendPopup = new javax.swing.JPopupMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();
        friendName = new javax.swing.JLabel();
        statusPanel = new javax.swing.JPanel();
        transferPanel = new javax.swing.JPanel();

        jMenuItem1.setText("Paste");
        friendPopup.add(jMenuItem1);

        jMenuItem2.setText("Remove friend");
        friendPopup.add(jMenuItem2);
        friendPopup.add(jSeparator1);

        jMenuItem3.setText("Connect");
        friendPopup.add(jMenuItem3);

        jMenuItem4.setText("Disconnect");
        friendPopup.add(jMenuItem4);

        setBackground(backgroundNormal);
        addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                formMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                formMouseExited(evt);
            }
        });

        friendName.setText("jLabel1");
        friendName.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                friendNameMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                friendNameMouseExited(evt);
            }
        });

        statusPanel.setBackground(new java.awt.Color(102, 255, 0));

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 14, Short.MAX_VALUE)
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 16, Short.MAX_VALUE)
        );

        transferPanel.setLayout(new javax.swing.BoxLayout(transferPanel, javax.swing.BoxLayout.Y_AXIS));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(statusPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(friendName, javax.swing.GroupLayout.DEFAULT_SIZE, 223, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(transferPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 237, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(statusPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(friendName))
                .addGap(0, 0, 0)
                .addComponent(transferPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

private void formMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseEntered
    setBackground(backgroundHighlight);
}//GEN-LAST:event_formMouseEntered

private void formMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseExited
    setBackground(backgroundNormal);
}//GEN-LAST:event_formMouseExited

private void friendNameMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_friendNameMouseEntered
    setBackground(backgroundHighlight);
}//GEN-LAST:event_friendNameMouseEntered

private void friendNameMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_friendNameMouseExited
    setBackground(backgroundNormal);
}//GEN-LAST:event_friendNameMouseExited


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel friendName;
    private javax.swing.JPopupMenu friendPopup;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JPanel statusPanel;
    private javax.swing.JPanel transferPanel;
    // End of variables declaration//GEN-END:variables

}
